﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web.Services;
using mal.balades.Business.Log;
using Mal.Balades.AdminBusiness.DataAccess;
using Mal.Balades.AdminBusiness.DataModel;

namespace mal.balades.Web.Administration
{
    /// <summary>
    /// Summary description for AdminWebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class AdminWebService : System.Web.Services.WebService
    {



        #region Fields
        private AdminDataAccess dataAccess;
        #endregion

        #region Construction / Destruction
        public AdminWebService()
        {
            dataAccess = new AdminDataAccess();
        }
        #endregion

        #region OperationContract
        [WebMethod]
        public List<VisitDashboard> GetVisitsForDashboard()
        {
            MalLogManager.WebLogger.Info("");
            ReadOnlyCollection<VisitDashboard> results = dataAccess.GetVisitsForDashboard();

            return results.ToList();
        }

        [WebMethod]
        public VisitAdmin GetVisit(int visitId)
        {
            MalLogManager.WebLogger.InfoFormat("visitId:{0}", visitId);
            VisitAdmin result = dataAccess.GetVisit(visitId);

            return result;
        }

        [WebMethod]
        public List<Mal.Balades.AdminBusiness.DataModel.Picture> GetVisitPictures(int visitId)
        {
            MalLogManager.WebLogger.InfoFormat("visitId:{0}", visitId);
            ReadOnlyCollection<Mal.Balades.AdminBusiness.DataModel.Picture> results = dataAccess.GetVisitPictures(visitId);

            return results.ToList();
        }

        [WebMethod]
        public List<Mal.Balades.AdminBusiness.DataModel.Information> GetVisitInformations(int visitId)
        {
            MalLogManager.WebLogger.InfoFormat("visitId:{0}", visitId);
            ReadOnlyCollection<Mal.Balades.AdminBusiness.DataModel.Information> results = dataAccess.GetVisitInformations(visitId);

            return results.ToList();
        }

        [WebMethod]
        public SaveVisitResult SaveVisit(SaveVisitObject visitToSave)
        {
            MalLogManager.WebLogger.Info("");
            SaveVisitResult result = dataAccess.SaveVisit(visitToSave);
            return result;
        }

        [WebMethod]
        public List<Mal.Balades.AdminBusiness.DataModel.PictureType> GetPicturesTypes()
        {
            MalLogManager.WebLogger.Info("");
            return dataAccess.GetPicturesTypes();
        }

        [WebMethod]
        public List<Mal.Balades.AdminBusiness.DataModel.InformationType> GetInformationTypes()
        {
            MalLogManager.WebLogger.Info("");
            return dataAccess.GetInformationTypes();
        }

        [WebMethod]
        public List<Category> GetCategories()
        {
            MalLogManager.WebLogger.Info("");
            return dataAccess.GetCategories();
        }

        [WebMethod]
        public List<FeedAdmin> GetFeeds()
        {
            MalLogManager.WebLogger.Info("");
            return dataAccess.GetFeeds();
        }

        [WebMethod]
        public void UpdateFeedItems(int feedId)
        {
            MalLogManager.WebLogger.InfoFormat("feedId:{0}", feedId);
            dataAccess.UpdateFeedItems(feedId);
        }
        #endregion
    }
}
